/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 *//*

package cz.worsik.android.test.rideshare.util.listener;

import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import cz.worsik.android.test.rideshare.R;
import cz.worsik.android.test.rideshare.MainActivity;

public class UlozCestujicihoListener implements View.OnClickListener
{
	MainActivity a;

	public UlozCestujicihoListener(MainActivity a) {
		this.a = a;
	}
	
	public void onClick(View v) {

		View view = a.popup_window.getContentView();

		EditText jmeno_input = (EditText) view.findViewById(R.id.popup_jmeno);
		EditText cena_input = (EditText) view.findViewById(R.id.popup_cena);
		CheckBox ridi_input = (CheckBox) view.findViewById(R.id.popup_ridi_check);

		Boolean ridi = ridi_input.isChecked();
		String jmeno = jmeno_input.getText().toString();
		int cena = 0;
		if (ridi) {
			cena = Integer.parseInt(cena_input.getText().toString());
		}

		String error = "\n";

		if (ridi && cena == 0)
		{
			error += a.getString(R.string.err_null_amount)+"\n";
		}

		if (!"\n".equals(error))
		{
			a.showToast(error, false);
			return;
		}

		Long retval;

		a.getDb().open();
		if (ridi) {
			retval = a.getDb().insertDriver(jmeno, cena);
		}
		else {
			retval = a.getDb().insertContact(jmeno);
		}
		a.getDb().close();

		if (retval > 0) {
			a.showToast(a.getString(R.string.msg_contact_saved, jmeno), false);
		}
		else {
			a.showToast(a.getString(R.string.msg_contact_not_saved), false);
		}

		a.generateLayout();
		a.generateBilanceTables();
		a.generateSettings();
		a.popup_window.dismiss();
	}
}*/
